<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">&lt;?php
<span id='global-property-'>/**
</span> * Cube PHP Framework
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the &quot;License&quot;); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * @author Dillen / Steffen
 */

namespace Library;
 
<span id='Library-Autoloader'>/**
</span> * Library.Autoloader is responsible for loading the classes of the framework. If you want, you can route your own namespace to a
 * specific path.
 * 
 * @class Library.Autoloader
 */
class Autoloader
{
<span id='Library-Autoloader-property-_namespaces'>	/**
</span>	 * Stores the namespace as key and it's path as value
	 * 
	 * @property {Array} _namespaces
	 * @private
	 */
	private $_namespaces = array();
	
<span id='Library-Autoloader-method-registerNamespace'>	/**
</span>	 * Register namespace
	 * 
	 * @method registerNamespace
	 * @param {String} $namespace
	 * @param {String} $path
	 */
	public function registerNamespace($namespace, $path)
	{
		$this-&gt;_namespaces[$namespace] = strtolower($path);
	}
	
<span id='Library-Autoloader-method-autoload'>	/**
</span>	 * Autoload method
	 * 
	 * This method is called my spl_autoload_register in Library.Application
	 * 
	 * @method autoload
	 * @param {String} $classname
	 */
	public function autoload($classname)
	{
		$path = explode('\\', $classname);
		$filename = array_pop($path);
		$clean_path = strtolower(implode('/', $path)) . '/' . $filename . '.php';
		
		if (file_exists($clean_path))
		{
			include($clean_path);
			return;
		}
		else
		{
			$clean_path = implode('/', $path) . '/' . $filename . '.php';
			
			foreach($this-&gt;_namespaces as $namespace =&gt; $new_path)
			{
				if ($namespace == str_replace('/', '\\', dirname($clean_path)))
				{
					if (file_exists($new_path . '/' . $filename . '.php'))
					{
						include($new_path . '/' . $filename . '.php');
						return;
					}
				}
			}
		}
		
		throw new Autoloader\Exception\ClassNotFoundException('Class ' . $classname . ' could not be found.');
	}
}</pre>
</body>
</html>
